home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 7459 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.1 KB  |  93 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: comp.vuw.ac.nz!HERMES!maths!peterm
  3. From: peterm@maths.grace.cri.nz (Peter McGavin)
  4. Subject: Re: AddIntServer + VERTB strangeness
  5. Message-ID: <PETERM.96Apr17120442@tui.maths.irl.cri.nz>
  6. Date: 17 Apr 1996 00:04:42 GMT
  7. References: <PETERM.96Apr7124019@tui.maths.irl.cri.nz>
  8.     <1084.6678T720T2089@Redrobe.demon.co.uk>
  9. Organization: Industrial Research Ltd
  10. In-reply-to: Mike@Redrobe.demon.co.uk's message of 14 Apr 96 12:00:41 +0000
  11.  
  12. Mike@Redrobe.demon.co.uk (Mike Redrobe) writes:
  13. >could you perhaps post (or upload to aminet) an input handler source?
  14. >This seems to be the "major" overhead, and may go some way to convince people
  15. >to use this method, over "more common" throttle the OS methods..
  16.  
  17. I'm not near my Amiga at the moment, but here's some C code clipped
  18. from one of my sources (and slightly rearranged --- sorry if I
  19. introduced any bugs).
  20. --
  21. Peter McGavin.   (p.mcgavin@irl.cri.nz)
  22. ------------------------------------------------------------------------
  23.  
  24. #include <devices/input.h>
  25.  
  26. struct Interrupt input_handler;
  27. struct MsgPort *mp = NULL;
  28. struct IOStdReq *io = NULL;
  29. BOOL input_is_open = FALSE;
  30.  
  31. __interrupt __asm /* __saveds */
  32. struct InputEvent *handler (register __a0 struct InputEvent *ie,
  33.                             register __a1 APTR data)
  34. /* This handler is passed a -list- of input events.  Handlers are allowed to
  35.    selectively remove individual entries or even add new entries.  Returning
  36.    NULL simply removes the lot.  Use __saveds to access globals (or better
  37.    still, pass everything required in a structure pointed to by data).
  38.    The RKMs recommend writing input-handlers in asm for speed, because
  39.    input-handlers are called often.  */
  40. {
  41.   while (ie != NULL) {
  42.     /* grab raw keyboard/mouse/timer input from ie->ie_Class and
  43.        other input-event fields here */
  44.     ie = ie->ie_NextEvent;
  45.   }
  46.   return NULL;
  47. }
  48.  
  49. BOOL install_handler (void)
  50. {
  51.   if ((mp = CreatePort (NULL, 0)) == NULL)
  52.     return FALSE;
  53.   if ((io = (struct IOStdReq *)CreateExtIO (mp, sizeof(struct IOStdReq))) == NULL)
  54.     return FALSE;
  55.   if (OpenDevice ("input.device", 0, (struct IORequest *)io, 0) != 0)
  56.     return FALSE;
  57.   input_is_open = TRUE;
  58.   input_handler.is_Code = (void (*)())handler;
  59.   input_handler.is_Data = NULL;  /* pass any pointer you want to the handler here */
  60.   input_handler.is_Node.ln_Pri = 100;  /* handlers are called in priority order */
  61.     /* Intuition and console.device handlers are about priority 50, from memory */
  62.   input_handler.is_Node.ln_Name = "my_input_handler";
  63.   io->io_Data = &input_handler;
  64.   io->io_Command = IND_ADDHANDLER;
  65.   DoIO ((struct IORequest *)io);
  66.   return TRUE;
  67. }
  68.  
  69. void cleanup_handler (void)
  70. /* call cleanup_handler() even if install_handler() fails */
  71. {
  72.   int i;
  73.  
  74.   if (input_is_open) {
  75.     io->io_Data = &input_handler;
  76.     io->io_Command = IND_REMHANDLER;
  77.     DoIO ((struct IORequest *)io);
  78.     CloseDevice ((struct IORequest *)io);
  79.     input_is_open = FALSE;
  80.   }
  81.   if (io != NULL) {
  82.     DeleteExtIO ((struct IORequest *)io);
  83.     io = NULL;
  84.   }
  85.   if (mp != NULL) {
  86.     DeletePort (mp);
  87.     mp = NULL;
  88.   }
  89. }
  90. -- 
  91. Peter McGavin.   (p.mcgavin@irl.cri.nz)
  92.  
  93.